package com.dhf.framework.system.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.dhf.framework.base.mybatis.core.page.Pagination;
import com.dhf.framework.common.BaseController;
import com.dhf.framework.system.entity.WbGoodsName;
import com.dhf.framework.system.service.WbGoodsNameService;

/**
 * 
* @ClassName: WbGoodsNameController
* @Description: TODO
* @author dahaofeng
* @date 2016-5-29 下午6:05:23
*
 */
@Controller
@RequestMapping("system/wbGoodsName")
public class WbGoodsNameController extends BaseController {

	private static Logger LOGGER = LoggerFactory.getLogger(WbGoodsNameController.class);
	
	@Autowired
	private WbGoodsNameService	wbGoodsNameService;

	/**
	 * 
	* @Title: queryPageList
	* @Description: 列表页面
	* @param @param searchEntity
	* @param @param pagination
	* @return ModelAndView    返回类型
	* @throws
	 */
	@RequestMapping(value = "/queryPageList")
	public ModelAndView queryPageList(WbGoodsName wbGoodsName, Pagination<WbGoodsName> pagination, HttpServletRequest request, HttpServletResponse response) {
		LOGGER.debug(WbGoodsNameController.class.getName()+":开始查询分页数据！");
		ModelAndView mv = new ModelAndView( "system/wbGoodsName/wbGoodsNameList" );
		pagination = this.wbGoodsNameService.queryPageList( wbGoodsName, pagination );
		mv.addObject( "pagination", pagination );
		return mv;
	}
	
	/**
	 * 
	* @Title: toMerge
	* @Description: 新增或修改页面
	* @param @param entity
	* @return ModelAndView    返回类型
	* @throws
	 */
	@RequestMapping(value = "/toMerge")
	public ModelAndView toMerge(WbGoodsName entity){
		ModelAndView mv = new ModelAndView("system/wbGoodsName/wbGoodsNameMerge");
		if(entity.getId() != null){
			WbGoodsName wbGoodsName =  this.wbGoodsNameService.get( entity.getId() ) ;
			mv.addObject("wbGoodsName",wbGoodsName);
		}else{
			mv.addObject("wbGoodsName", new WbGoodsName());
		}
		return mv;
	}

	/**
	 * 
	* @Title: doMerge
	* @Description: 新增或修改数据 
	* @param @param request
	* @param @param entity
	* @return ModelAndView    返回类型
	* @throws
	 */
	@RequestMapping(value = "/doMerge")
	public ModelAndView doMerge(WbGoodsName entity,RedirectAttributes redirectAttributes) {
	    ModelAndView view=new ModelAndView( "redirect:/system/wbGoodsName/queryPageList.do" );
	    if (!beanValidator(view, entity)){
            return view;
        }
		if (entity.getId()!=null) {
			LOGGER.debug(WbGoodsNameController.class.getName()+":开始更新数据！");
			this.wbGoodsNameService.update( entity );
			this.addMessage(redirectAttributes, "修改数据成功");
		} else {
			LOGGER.debug(WbGoodsNameController.class.getName()+":开始新增数据！");
			this.wbGoodsNameService.add( entity );
			this.addMessage(redirectAttributes, "新增据成功");
		}
		return view;
	}

	/**
	 * 
	* @Title: delete
	* @Description:删除数据
	* @param @param id
	* @return ModelAndView    返回类型
	* @throws
	 */
	@RequestMapping(value = "/delete")
	public ModelAndView delete(Long id,RedirectAttributes redirectAttributes) {
		LOGGER.debug(WbGoodsNameController.class.getName()+":开始删除数据！");
        this.wbGoodsNameService.delete( id );
        this.addMessage(redirectAttributes, "删除数据成功");
        return new ModelAndView( "redirect:/system/wbGoodsName/queryPageList.do" );
	}

}